package ca.jerg.wizard;

import javax.swing.*;
import java.awt.event.*;
import java.awt.Dimension;
import java.awt.BorderLayout;

import ca.jerg.config.*;
import ca.jerg.layout.SpringUtilities;

public class ErgWizardSetPanel extends JPanel implements ActionListener
{
	private static final long serialVersionUID = 1L;

	private JLabel titleText;
	private JComboBox setType;
	//private JTextArea setDetails;
	private JLabel setDetails;
	private JTextField numRepeats;
	private ErgConfigWorkDetails details;
	
	public ErgWizardSetPanel() 
    {   	               
		details = new ErgConfigWorkDetails();
		
		setLayout(new BorderLayout());
		add(getContentPanel());
		
		setPanelText("Set 1");
    }
	
	public ErgWizardSetPanel( int num ) 
    {   	          
		details = new ErgConfigWorkDetails();
		
		setLayout(new BorderLayout());		
		add(getContentPanel());
		
		setPanelText("Set " + num);		
    }
	
	public void setPanelText( String text )
	{
		titleText.setText(text);
	}
	
	public String getType()
	{
		return (String)setType.getSelectedItem();
	}
	
	public String getNumRepeats()
	{
		return numRepeats.getText();
	}
		
	//@Override
	public void actionPerformed( ActionEvent event )
	{
		setDetails.setText("<html>" + 
				details.getString((String)setType.getSelectedItem(),null) + 
				"</html>");
	}
	
	private JPanel getContentPanel()
	{		
		JPanel detailsPanel = new JPanel();
		detailsPanel.setLayout(new BorderLayout());
				
		// set type
		setType = new JComboBox(IErgConfig.keys);
		setType.setToolTipText("Select the type of set to generate.");
		setType.addActionListener(this);
		JLabel jLabel1 = new JLabel("Select Set");
		jLabel1.setLabelFor(setType);
		
		// number of repeats
		numRepeats = new JTextField("1");
		numRepeats.setToolTipText("Enter the number repeats to perform.");
		JLabel jLabel2 = new JLabel("Number of repeats");
		jLabel2.setLabelFor(numRepeats);
		
		// set number reference	
		titleText = new JLabel();		
		titleText.setPreferredSize(new Dimension(370,50));		
		titleText.setHorizontalAlignment(SwingConstants.CENTER);
		titleText.setRequestFocusEnabled(false);
		
		// set detail reference
		setDetails = new JLabel("<html>" +
				details.getString((String)setType.getSelectedItem(),null) +
				"</html>");
		setDetails.setPreferredSize(new Dimension(370,50));
		setDetails.setHorizontalAlignment(SwingConstants.CENTER);
		setDetails.setRequestFocusEnabled(false);
				
		JPanel panel = new JPanel();
		panel.setLayout(new SpringLayout());
		panel.add(jLabel1);
		panel.add(setType);
		panel.add(jLabel2);
		panel.add(numRepeats);
		SpringUtilities.makeCompactGrid(panel,2,2,6,6,6,6);
		
		detailsPanel.add(titleText,BorderLayout.NORTH);
		detailsPanel.add(panel,BorderLayout.CENTER);
		detailsPanel.add(setDetails,BorderLayout.SOUTH);
		
		JPanel contentPanel = new JPanel();
		contentPanel.setLayout(new BorderLayout());
		contentPanel.add(detailsPanel,BorderLayout.CENTER);
		
		return contentPanel;		
	}
}
